using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
    public class MRPDetailsRequirementService
    {
        ISession session;

        public MRPDetailsRequirementService(ISession session)
        {
            this.session = session;
        }
        public MRPDetailsRequirementService()
        {
            this.session = SessionFactory.GetNewSession();
        }
        public void InsertMrpdetailsrequirement(MRPDetailsRequirement mrpdetailsrequirementX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpdetailsrequirementX);
            tx.Commit();
        }

        public void UpdateMrpdetailsrequirement(MRPDetailsRequirement mrpdetailsrequirementX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpdetailsrequirementX);
            tx.Commit();
        }

        public void DeleteMrpdetailsrequirement(MRPDetailsRequirement mrpdetailsrequirementX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpdetailsrequirementX);
            tx.Commit();
        }

        public IList<MRPDetailsRequirement> GetAllMrpdetailsrequirement(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPDetailsRequirement");
            IList<MRPDetailsRequirement> list = query.List<MRPDetailsRequirement>();
            if (evict)
            {
                foreach (MRPDetailsRequirement s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPDetailsRequirement GetAllMrpdetailsrequirementByID(String id, Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPDetailsRequirement as c where c.Detailmanufacturerequirementid= :x");
            query.SetString("x", id);
            MRPDetailsRequirement s = (MRPDetailsRequirement)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPDetailsRequirement> GetMrpdetailsrequirementByQuery(IQuery query, Boolean evict)
        {
            IList<MRPDetailsRequirement> list = query.List<MRPDetailsRequirement>();
            if (evict)
            {
                foreach (MRPDetailsRequirement s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }
    }
}
